const Router = require('koa-router')
const router = new Router()
const request = require('request')

router.get('/zhihu/hot/list', async (ctx) => { // 知乎热报
  const getData = () => {
    return new Promise((resolve, reject) => {
      request('https://news-at.zhihu.com/api/3/news/hot', (err, res, body) => {
        resolve(body)
      })
    })
  }

  const data = await getData()
  ctx.body = data
})

router.get('/zhihu/hot/detail', async (ctx) => { // 知乎热报
  const url = ctx.query.url

  const getData = () => {
    return new Promise((resolve, reject) => {
      request(url, (err, res, body) => {
        resolve(body)
      })
    })
  }

  const data = await getData()
  ctx.body = data
})

module.exports = router